import 'package:convergence_media/features/config/theme/app_theme_data.dart';
import 'package:convergence_media/interceptors/interceptor_init.dart';
import 'package:convergence_media/l10n/l10n.dart';
import 'package:convergence_media/navigator/app_router.dart';
import 'package:convergence_media/navigator/app_router_observer.dart';
import 'package:device_preview/device_preview.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class App extends HookConsumerWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final appRouter = useMemoized(() => ref.watch(appRouterProvider));

    // interceptorsInit(ref);

    return MaterialApp.router(
      theme: appThemeData,
      localizationsDelegates: AppLocalizations.localizationsDelegates,
      supportedLocales: AppLocalizations.supportedLocales,
      routerConfig: appRouter.config(
        navigatorObservers: () => [
          AppRouterObserver(),
        ],
      ),
      debugShowCheckedModeBanner: false,
      // 设备效果预览
      locale: DevicePreview.locale(context),
      builder: (context, child) {
        return DevicePreview.appBuilder(
          context,
          ScreenUtilInit(
            designSize: const Size(411, 731),
            minTextAdapt: true,
            splitScreenMode: true,
            builder: (context, child) => child ?? const Placeholder(),
            child: child,
          ),
        );
      },
    );
  }
}
